package com.puboot.module.blog.service.impl;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.puboot.module.blog.service.SMSService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created with IntelliJ IDEA.
 * User: 梁亮
 * Date: 2021/11/12
 * Time: 14:39
 * To change this template use File | Settings | File Templates.
 * Description:
 */
@Service
public class SMSServiceImpl implements SMSService {

    @Autowired
    private Client client;

    @Override
    public SendSmsResponse sendSMS(String code, String phone) throws Exception {
        return sendSMS(code, phone, "中科碳和", "SMS_227738425");
    }

    @Override
    public SendSmsResponse sendForgetSMS(String code, String phone) throws Exception {
        return sendSMS(code, phone, "中科碳和", "SMS_232175338");
    }

    @Override
    public SendSmsResponse sendSMS(String code, String phone, String signName, String templateCode) throws Exception {
        SendSmsRequest sendSmsRequest = new SendSmsRequest();
        sendSmsRequest.setPhoneNumbers(phone);
        //短信签名
        sendSmsRequest.setSignName(signName);
        //短信模版
        sendSmsRequest.setTemplateCode(templateCode);
        sendSmsRequest.setTemplateParam("{\"code\":\"" + code + "\"}");
        // 复制代码运行请自行打印 API 的返回值
        SendSmsResponse sendSmsResponse = client.sendSms(sendSmsRequest);
        return sendSmsResponse;
    }
}